package com.woniu.controller;

import com.woniu.entity.Constant;
import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.Gym;
import com.woniu.service.IGymService;
import com.woniu.vo.GymQueryImgVo;
import com.woniu.vo.GymQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dong
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/gym")
@Api(tags = "场馆管理")
public class GymController extends BaseController{

    @Autowired
    private IGymService gymService;

    @ApiOperation("分页搜索")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody GymQueryVo gymQueryVo){
        PageResult pageResult = gymService.search(currentPage, pageSize, gymQueryVo);
        return toDataResult(pageResult);
    }

    @ApiOperation("增加")
    @PostMapping
    public Result add(@RequestBody Gym gym){
        boolean flag = gymService.save(gym);
        return toResult(flag);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result modify(@RequestBody Gym gym){
        boolean flag = gymService.updateById(gym);
        return toResult(flag);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable String id){
        boolean flag = gymService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable String id){
        Gym gym = gymService.getById(id);
        return toDataResult(gym);
    }

    @ApiOperation("查询所有")
    @GetMapping("/queryAll")
    public Result queryAll(){
        List<Gym> gymList = gymService.list();
        return toDataResult(gymList);
    }


    @ApiOperation("查询所有场馆")
    @GetMapping
    public Result queryGymAll(){
        List<Gym> gymList = gymService.queryGymAll();
        return toDataResult(gymList);
    }

    @ApiOperation("模糊搜索")
    @PostMapping("/{name}")
    public Result queryByName(@PathVariable String name){
        List<Gym> gymList = gymService.queryByName(name);
        return toDataResult(gymList);
    }

    @ApiOperation("根据场馆id查询")
    @GetMapping("/img/{id}")
    public Result queryByImg(@PathVariable String id){
        List<GymQueryImgVo> gymQueryImgVoList = gymService.queryByImg(id);
        return toDataResult(gymQueryImgVoList);
    }


}
